<template>
	<block>
		<hxt-layout id="hxt-layout" title="富文本" svc="img" initTitle="富文本加载失败" @initPage="initPage">
			<view class="hxt-flex-column" style="background-color: #fff;">
				<hxt-scroll ref="scrollEL" id="scrollEL" scroll-y style="height:100%;" scroll-with-animation="true"
					enable-back-to-top="true" :enhanced="true" :bounces="false" @loadData="loadData">
					<van-cell :title="item.title" is-link v-for="(item,index) in list" @click="open(item)"></van-cell>
				</hxt-scroll>
			</view>
		</hxt-layout>
		<page-container v-if="!!detail.show" :show="detail.show" @clickoverlay="detail.show=false"
			@afterleave="detail.show=false" custom-style="height:100vh;overflow:hidden;" position="bottom" :z-index="9">
			<web-view :src="domain+'pc/wangEditorShare?id='+detail.obj.id"></web-view>
		</page-container>
		<hxt-loading id="hxt-loading"></hxt-loading>
	</block>
</template>

<script>
	import hxt from "@/utils/hxt.js"
	export default {
		data() {
			const app = getApp();
			return {
				list: [],
				currentUser: app.globalData.currentUser,
				domain: hxt.domain,
				query: {
					pageIndex: 1,
					pageSize: 30,
					rowCount: 0,
				},
				detail: {
					show: false,
					obj: null
				},
			}
		},
		onShow: function(e) {},
		methods: {
			initPage: function(e) { //初始化事件
				var _this = this;
				_this.loadData();
			},
			loadData: function(e) {
				var _this = this;
				if (!e || e.refresh) {
					_this.query.pageIndex = 1;
				};
				hxt.post({
					url: hxt.domain + 'pc/wangEditorList',
					data: {
						openId: _this.currentUser.openId,
						pageIndex: _this.query.pageIndex,
						pageSize: _this.query.pageSize
					},
					ok: function(res) {
						if (res.data.code != 0) {
							return hxt.Notify({
								message: '加载失败：' + res.errMsg + '，请稍后重试！'
							});
							_this.$refs.scrollEL.refreshDone(false);
							return;
						};
						var list = _this.query.pageIndex == 1 ? [] : _this.list;
						_this.list = list.concat(res.data.data.list);
						_this.$refs.scrollEL.refreshDone(_this.query.pageIndex <= (
							parseInt(res.data.data.rowCount / res.data.data.pageSize)));
						_this.query.pageIndex++;
						_this.query.pageSize = res.data.data.pageSize;
						_this.query.rowCount = res.data.data.rowCount;
					},
					fail: function(res) {
						hxt.Notify({
							type: 'danger',
							message: '加载失败：' + res.errMsg + '，请稍后重试！'
						});
						_this.$refs.scrollEL.refreshDone(false);
					}
				});
			},
			open: function(item) {
				var _this = this;
				_this.detail.obj = item;
				_this.detail.show = true;
			}
		}
	}
</script>

<style>
</style>